﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

using Tour.Helper;
/// <summary>
///TourExtern 的摘要说明
/// </summary>
public static class TourExtern
{
    public static int ToInt(this object o)
    {
        return PagerHelper.GetInt(o);
    }

    public static void AlertMessage(this System.Web.UI.Page page, string message, string returnUrl)
    {
        if (!message.IsNullOrEmpty() || !returnUrl.IsNullOrEmpty())
        {
            StringBuilder sb = new StringBuilder("<script>");
            if (!message.IsNullOrEmpty())
            {
                sb.Append(string.Format("alert('{0}');", message));
            }
            if (!returnUrl.IsNullOrEmpty())
            {
                sb.Append(string.Format("location.href='{0}';", returnUrl));
            }
            sb.Append("</script>");
            page.RegisterClientScriptBlock("alertMessage", sb.ToString());
        }
    }

    public static bool ToBoolean(this object o)
    {
        bool result = false;
        try
        {
            result = Convert.ToBoolean(o);
        }
        catch { }
        return result;
    }

    public static bool IsNullOrEmpty(this string str)
    {
        return String.IsNullOrEmpty(str);
    }
}
